package tech.hypersense.common.core.exception;

import lombok.Getter;
import org.slf4j.helpers.MessageFormatter;
import tech.hypersense.common.core.domain.result.base.IResultCode;

/**
 * @Author: HyperSense
 * @CreateTime: 2025-03-25
 * @Description: 自定义业务异常
 * @Version: 1.0
 */
@Getter
public class BusinessException extends RuntimeException {

    public IResultCode resultCode;

    public BusinessException(IResultCode errorCode) {
        super(errorCode.getMsg());
        this.resultCode = errorCode;
    }


    public BusinessException(IResultCode errorCode,String message) {
        super(message);
        this.resultCode = errorCode;
    }


    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    public BusinessException(String message, Object... args) {
        super(formatMessage(message, args));
    }

    private static String formatMessage(String message, Object... args) {
        return MessageFormatter.arrayFormat(message, args).getMessage();
    }

}
